package com.lxw.study.structural.facade.case1;

public class OnlineShoppingFacade {
    private InventorySystem inventorySystem;
    private OrderSystem orderSystem;
    private EmailNotificationSystem emailNotificationSystem;

    public OnlineShoppingFacade() {
        this.inventorySystem = new InventorySystem();
        this.orderSystem = new OrderSystem();
        this.emailNotificationSystem = new EmailNotificationSystem();
    }

    // 提供一个简化的接口，让客户端可以通过一个方法完成整个购物流程
    public void purchase(String productId, int quantity, String customerName, String customerEmail) {
        System.out.println("开始购物流程...");
        boolean stockAvailable = inventorySystem.checkStock(productId, quantity);

        if (stockAvailable) {
            String orderId = orderSystem.generateOrder(productId, quantity, customerName);
            emailNotificationSystem.sendOrderConfirmationEmail(orderId, customerEmail);
            System.out.println("购物流程完成");
        } else {
            System.out.println("库存不足，购物流程失败");
        }
    }
}
